<template>
  <div>
    <div class="container radiusBottom">
      <div class="images">
        <div class="img">
          <img :src="styleUrls[dataJson.type][dataJson.stylesType]" />
        </div>
        <div class="buttonSetStyle" @click="alertTag">修改样式</div>
      </div>
    </div>
    <div>
      <div
        v-for="(item, index) in dataJson.imgUrls"
        :key="index"
        class="container"
        draggable="true"
        @dragstart.capture="dragstartListSort(index, $event)"
        @drop.stop="dropListSort(index, $event, 'imgUrls')"
        @dragover.prevent="dragoverListSort"
      >
        <div class="title">
          图片{{ index + 1 }}
          <span v-if="index > 0" class="del" @click="deleteCurItemImg(index)"
            >删除</span
          >
        </div>

        <div class="line">
          <div class="left">选择图片</div>
          <div class="imgContent">
            <img v-if="!item.src" :src="Images.lunbo_img_style1" />
            <img v-else :src="item.src" />
            <p class="describe">建议尺寸：750px*360px</p>
          </div>
          <div>
            <el-button class="btn" @click="showdialog(index)"
              >上传图片</el-button
            >
          </div>
        </div>
        <div class="line">
          <div class="left">图片链接</div>
          <el-tooltip
            class="item"
            effect="dark"
            :content="item.jump_name"
            placement="bottom"
          >
            <el-button @click="chooseLink(index)">
              {{ item.jump_name ? item.jump_name : "选择链接" }}</el-button
            >
          </el-tooltip>
        </div>
      </div>
    </div>
    <div class="container">
      <el-button :disabled="dataJson.imgUrls.length === 10" @click="addimg"
        >添加图片</el-button
      >
      <span class="line-heiht_40 ">上下拖动可排序</span>
    </div>
  </div>
</template>

<script>
import { styleUrls } from "../../data";
export default {
  props: {
    dataJson: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      styleUrls
    };
  },
  methods: {
    dragstartListSort(index, e) {
      this.$emit("dragstartListSort", index, e);
    },
    dropListSort(index, e, attr) {
      this.$emit("dropListSort", index, e, attr);
    },
    dragoverListSort() {},
    deleteCurItemImg(index) {
      this.dataJson.imgUrls.splice(index, 1);
    },
    showdialog(index) {
      this.$emit("showdialog", index);
    },
    chooseLink(index) {
      this.$emit("chooseLink", index);
    },
    addimg() {
      this.dataJson.imgUrls.push(
        JSON.parse(JSON.stringify(this.dataJson.imgUrls[0]))
      );
      this.dataJson.imgUrls[
        this.dataJson.imgUrls.length - 1
      ].id = this.dataJson.imgUrls.length;
    },
    alertTag() {
      this.$emit("alertTag", true, this.dataJson.stylesType, 34);
    }
  }
};
</script>

<style lang="scss" scoped>
@import "~@/assets/scss/decorate.scss";
</style>
